// pages/service/index.js
import { getAllNews} from "../../api/news";
import { studentGetInfo } from "../../api/manage";

Page({
  data: {
    newsItem:[],
    avatar:null,
    username:null,
    studentno:null,
    major:null
  },
  onShow() {
    if (typeof this.getTabBar === 'function' && this.getTabBar()) {
      this.getTabBar().setData({
        selected: 1
      });
    }
    const userID=wx.getStorageSync('userID');

    studentGetInfo(userID).then(res=>{
      this.setData({
         username:res.data.studentName,
         studentno:res.data.studentNo,
         major:res.data.major,
         avatar:res.data.avatar
      })
    });
  },
  async onLoad(){
    const userID=wx.getStorageSync('userID');
    studentGetInfo(userID).then(res=>{
      this.setData({
         username:res.data.studentName,
         studentno:res.data.studentNo,
         major:res.data.major,
         avatar:res.data.avatar
      })
    });
      const res = await getAllNews()
      let date=[]
      this.setData({
        newsItem:res.data[0]
      })
  },

    // 点击跳转校园卡页面
    onCampusCardClick() {
      // 跳转到校园卡页面
      wx.navigateTo({
        url: '/pages/campus_card/index', 
      });
    },
    // 校园地图
    onMapClick() {
      wx.navigateTo({
        url: '/pages/school_map/index', 
      });
    },
    // 意见反馈
    onBackClick() {
      wx.navigateTo({
        url: '/pages/feedback/index', 
      });
    },

    onChooseClassClick() {
      wx.navigateTo({
        url: '/pages/select_class/index', 
      });
    },
});
